package com.pb.camera.application;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import com.lidroid.xutils.BitmapUtils;
import com.pb.camera.bean.AllRoom;
import com.pb.camera.bean.UserGroups;
import com.pb.camera.lock.LockPatternUtils;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Environment;

public class App extends Application {
    private static App mInstance;
    private LockPatternUtils mLockPatternUtils;
    private String account;
    private String gesture;
    public  BitmapUtils bitmapUtils;
    public  String bitmapLocalPath;
    private String mobile;
    private String openId;
    private String password;
    private String userId;
    private String email;
    private AllRoom allRoom;

    private UserGroups userGroups;
    private String groupName;
    public boolean isAirConditionBinded;
    private ArrayList<Activity> allActivity = new ArrayList<Activity>();//保存Activity
    private String aleartRoom;//点击告警的房间号

    public String getAleartRoom() {
        return aleartRoom;
    }

    public void setAleartRoom(String aleartRoom) {
        this.aleartRoom = aleartRoom;
    }

    public ArrayList<Activity> getAllActivity() {
        return allActivity;
    }

    public void setAllActivity(ArrayList<Activity> allActivity) {
        this.allActivity = allActivity;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }


    public String getAccount() {
        return account;
    }


    public void setAccount(String account) {
        this.account = account;
    }

    public String getGesture() {
        return gesture;
    }

    public void setGesture(String gesture) {
        this.gesture = gesture;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getOpenId() {
        return openId;
    }

    public void setOpenId(String openId) {
        this.openId = openId;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public static App getInstance() {
        if (mInstance != null) {
            return mInstance;
        } else {
            return new App();

        }
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mInstance = this;
        bitmapLocalPath = getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath();
        bitmapUtils = new BitmapUtils(getApplicationContext(), bitmapLocalPath, 0.1f);
        mLockPatternUtils = new LockPatternUtils(this);
        //开启log记录的服务
//		CrashHandler crashHandler = CrashHandler.getInstance() ;
//		crashHandler.init(this) ;
    }

    public int getStatusBarHeight(Context context) {
        Class<?> c = null;
        Object obj = null;
        Field field = null;
        int x = 0, statusBarHeight = 0;
        try {
            c = Class.forName("com.android.internal.R$dimen");
            obj = c.newInstance();
            field = c.getField("status_bar_height");
            x = Integer.parseInt(field.get(obj).toString());
            statusBarHeight = context.getResources().getDimensionPixelSize(x);
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        return statusBarHeight;
    }

    public String stringFilter(String str) throws PatternSyntaxException {
        String regEx = "[/\\:*?<>|\"\n\t]"; //要过滤掉的字符
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        return m.replaceAll("").trim();
    }

    public LockPatternUtils getLockPatternUtils() {

        return mLockPatternUtils;
    }

    public AllRoom getAllRoom() {
        return allRoom;
    }

    public void setAllRoom(AllRoom allRoom) {
        this.allRoom = allRoom;
    }
    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }
    public UserGroups getUserGroups() {
        return userGroups;
    }

    public void setUserGroups(UserGroups userGroups) {
        this.userGroups = userGroups;
    }

}
